package com.TPsoft.cafe_server.GroupProfileList;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class GroupProfileListAdapter extends BaseAdapter {

	private Context musicContext;

	private List<GroupProfileItem> musicItemList = new ArrayList<GroupProfileItem>();

	public GroupProfileListAdapter(Context context) {
		musicContext = context;
	}

	public void addItem(GroupProfileItem it) {
		musicItemList.add(it);
	}
	
	public void removeItem(int position) {
		musicItemList.remove(position);
	}

	public void setListItems(List<GroupProfileItem> lit) {
		musicItemList = lit;
	}
	
	public void clear() {
		musicItemList.clear();
	}

	public int getCount() {
		return musicItemList.size();
	}

	public Object getItem(int position) {
		return musicItemList.get(position);
	}

	public boolean areAllItemsSelectable() {
		return false;
	}

	public boolean isSelectable(int position) {
		try {
			return musicItemList.get(position).isSelectable();
		} catch (IndexOutOfBoundsException ex) {
			return false;
		}
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		GroupProfileView itemView;
		if (convertView == null) {
			itemView = new GroupProfileView(musicContext, musicItemList.get(position));
		} else {
			itemView = (GroupProfileView) convertView;
			
			itemView.setIcon(musicItemList.get(position).getIcon());
			itemView.setText(0, musicItemList.get(position).getData(1));
			itemView.setText(1, musicItemList.get(position).getData(2));
			itemView.setText(2, musicItemList.get(position).getData(3));
		}

		return itemView;
	}

}
